package org.xinjiang.data.migration.hainan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xinjiang.data.migration.common.response.PageInfo;
import org.xinjiang.data.migration.common.response.Param;
import org.xinjiang.data.migration.common.utils.query.Pages;
import org.xinjiang.data.migration.common.utils.query.Queries;
import org.xinjiang.data.migration.hainan.convert.DcpgConvert;
import org.xinjiang.data.migration.hainan.dto.req.DcpgQueryDTO;
import org.xinjiang.data.migration.hainan.dto.res.DcpgResultDTO;
import org.xinjiang.data.migration.hainan.entity.DcpgEntity;
import org.xinjiang.data.migration.hainan.mapper.DcpgMapper;
import org.xinjiang.data.migration.hainan.service.IDcpgService;

@Service
public class DcpgServiceImpl extends ServiceImpl<DcpgMapper, DcpgEntity> implements IDcpgService {
    @Autowired
    private DcpgConvert dcpgConvert;

    @Override
    public PageInfo<DcpgResultDTO> pageList(Param pageable, DcpgQueryDTO dto) {
        IPage<DcpgEntity> page = this.page(Pages.page(pageable), wrapper(dto));
        return Pages.convert(page, dcpgConvert::convert);
    }

    private LambdaQueryWrapper<DcpgEntity> wrapper(DcpgQueryDTO query) {
        LambdaQueryWrapper<DcpgEntity> wrapper = Queries.lambda();
        Queries.accept(query.getId(), v -> wrapper.eq(DcpgEntity::getId, v));
        return wrapper;
    }
}
